#ifndef __IDT_H__
#define __IDT_H__

#include <asm/type.h>
#include <macros.h>

typedef struct
{
    u8_t v[16];           // reserved
} __attribute__((packed)) idt_entry_t;

extern idt_entry_t IdtTable[IDTNUM];

typedef struct
{
	u64_t es;
	u64_t ds;
	u64_t r15;
	u64_t r14;
	u64_t r13;
	u64_t r12;
	u64_t r11;
	u64_t r10;
	u64_t r9;
	u64_t r8;
	u64_t rbp;
	u64_t rdi;
	u64_t rsi;
	u64_t rdx;
	u64_t rcx;
	u64_t rbx;
	u64_t rax;
	u64_t func;
	u64_t errcode;
	u64_t rip;
	u64_t cs;
	u64_t rflags;
	u64_t rsp;
	u64_t ss;
} __attribute__((packed)) intr_arg_t;

static inline void set_trap_gate(u32_t n, u8_t ist, void *addr)
{
    _set_gate(IdtTable+n, 0x8f, ist, addr);  //P=1,DPL=0,TYPE=F
}

static inline void set_intr_gate(u32_t n, u8_t ist, void *addr)
{
    _set_gate(IdtTable+n, 0x8e, ist, addr);  //P=1,DPL=0,TYPE=E
}

static inline void set_sys_trap_gate(u32_t n, u8_t ist, void *addr)
{
    _set_gate(IdtTable+n, 0xef, ist, addr);  //P=1,DPL=3,TYPE=F
}

static inline void set_sys_intr_gate(u32_t n, u8_t ist, void *addr)
{
    _set_gate(IdtTable+n, 0xee, ist, addr);  //P=1,DPL=3,TYPE=E
}


extern void init_interrupt();

#endif